
package fileby.ctrl.actions.impl;

import fileby.model.ISourceHandler;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JTabbedPane;

/**
 *
 * @author Jacob
 */
class CloseTabAction extends AbstractAction {

    private ISourceHandler sourceHandler;

     public CloseTabAction(ISourceHandler sourceHandler) {
        super("X",null);
        this.sourceHandler = sourceHandler;
        putValue(SHORT_DESCRIPTION, "Close this tab");
    }

    public void actionPerformed(ActionEvent e) {
        int index = ((JTabbedPane) ((JComponent) ((JComponent)
                        ((JComponent) e.getSource()).getParent()).getParent()).
                        getParent()).indexOfTabComponent(((JComponent) ((JComponent)
                        e.getSource()).getParent()));
        sourceHandler.removeSource(index);
    }

}
